package com.nCoV.EpidemicSurveillance.repository;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Component;

import com.nCoV.EpidemicSurveillance.domain.DemoNode;

/**
 * @author 张浩田
 * @date 2020年3月10日
 */
@Component
public interface AddCsvRepository extends Neo4jRepository<DemoNode, Long>{
    
    @Query("LOAD CSV WITH HEADERS FROM 'file:///person.csv' AS line "
    		+ "merge (:Student{id:tostring(line.studentid),name:tostring(line.name),age:tostring(line.age)})")
    void addPersonNodes();
    
    @Query("LOAD CSV WITH HEADERS FROM 'file:///place.csv' AS line "
    		+ "merge (:Place{id:tostring(line.placeid),name:tostring(line.name)})")
    void addPlaceNodes();

    @Query("LOAD CSV WITH HEADERS FROM 'file:///relation.csv' AS line "
    		+ "match (from:Student{id:line.studentid}),(to:Place{name:line.placename})"
    		+ "merge (from)-[r:stay_at]->(to) "
    		+ "set r.starttime=tostring(line.starttime),r.endtime=tostring(line.endtime),"
    		+ "r.name=tostring(line.name)")
    void addRelation();
}
